<?php
/**
 * Created by PhpStorm.
 * User: ZCY
 * Date: 2018/11/21
 * Time: 17:58
 */

require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
$connection = new AMQPStreamConnection('192.168.100.108', 5672, 'zcy', '196000');
$channel = $connection->channel();

$channel->exchange_declare('logs', 'fanout', false, false, false);      //生成exchange

$channel->queue_declare("task_logs", false, false, false, false);      //生成queue

$channel->queue_bind("task_logs", 'logs');                            //queue綁定交換機

echo ' [*] Waiting for logs. To exit press CTRL+C', "\n";

$callback = function($msg){
    echo ' [x] ', $msg->body, "\n";
};

$channel->basic_consume("task_logs", '', false, false, false, false, $callback);

while(count($channel->callbacks)) {
    $channel->wait();
}
$channel->close();
$connection->close();

